﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace jinquantesthuiyuan_system
{
    public partial class HyEdit : Form
    {
        DataRow datarow;
        public HyEdit(DataRow row)
        {
            InitializeComponent();
            datarow = row;//用来接收数据
        }
        
        private void HyEdit_Load(object sender, EventArgs e)
        {
            textBox1.Text = DR2Str(datarow, "user");
            textBox2.Text = DR2Str(datarow, "phone");
            textBox3.Text = DR2Str(datarow, "pone码");
            //dateTimePicker1.Text = DR2Str(datarow, "xtime");
            textBox4.Text = DR2Str(datarow, "zye");
            textBox5.Text = DR2Str(datarow, "kye");
            textBox6.Text = DR2Str(datarow, "xje");

        }
        private string DR2Str(DataRow dr, string cn)
        {
            try
            {
                return dr[cn].ToString();
            }
            catch
            {
                return string.Empty;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //修改数据
            string str = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=huiyuan.accdb";//连接数据库
            try
            {
                OleDbConnection myconn = new OleDbConnection(str);
                myconn.Open();//打开数据库

                string s1 = textBox1.Text + textBox2.Text + textBox3.Text + textBox4.Text + textBox5.Text + textBox6.Text;

                string sql = "UPDATE `jq_huiyuan` SET ID=" + s1;//只能修改一条，并且只能是数字型
                //string sql = "update jq_huiyuan set 姓名='" + textBox1.Text + "',手机号码='" + textBox2.Text + "'";
                //string sql = "Update Categories set 姓名='" + textBox1.Text.Trim() + "',手机号码='" + textBox2.Text.Trim() + "' where CategoryID=";

                OleDbCommand inst = new OleDbCommand(sql, myconn);
                int se = inst.ExecuteNonQuery();
                if (se != 0)//判断是否执行成功
                {
                    MessageBox.Show("修改成功！");
                }
                else
                {
                    MessageBox.Show("修改失败！");
                }

                myconn.Close();//关闭数据
                Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("错误提示：" + "\r\n" + ex);
            }
        }
    }
}